package control;

import java.util.TreeSet;

/**
 * Eventhandler sorts and collects events
 * @author guru
 */
public class Eventhandler {

    static int time;
    private static TreeSet<Event> events = new TreeSet<Event>();

    public static void init() {
        time = 0;
    }

    /**
     * get simulation time
     * @return time as integer
     */
    public static int getTime() {
        return time;
    }

    /**
     * adds a new event to eventhandler
     * @param e
     */
    public static void add(Event e) {
        events.add(e);
    }

    /**
     * get the next event, removes it from list and update time
     * @return
     */
    public static Event getNext() {
        Event e = events.first();
        events.remove(e);
        time = e.getTime();
        return e;
    }
}
